System and methods for comparing documents

ABSTRACT

A method includes scanning a page of a paper document to generate a first digital page image. The method further includes obtaining a second digital page image which corresponds to a second page. The method also includes comparing the first digital page image pixel-by-pixel with the second digital page image to generate a score that indicates a degree to which the first digital page image differs from the second digital page image.

BACKGROUND

This invention is concerned with providing an automatic comparison oftwo documents.

When two documents are in the form of electronic text files, they can becompared quite readily by a standard function in conventional wordprocessing programs such as Microsoft Word. However, when both documentsare paper hard copies, or one is on paper and the other is an electronictext file, the task of comparing the documents becomes much moredifficult. Particular challenges are presented, for example, in the caseof verifying that two purported copies of a paper legal document (e.g.,a lengthy contract) are in fact identical in text. Conventionalpractices call for one human being to orally read out from one purportedcopy, while another human being follows along on the other purportedcopy. Even when the two individuals are highly skilled paralegals, sucha process may be time-consuming, tedious, and prone to error.

Another technique used to compare paper documents entails running boththrough an optical character recognition (OCR) scan. The two resultingelectronic text files may then be compared as if both had been generatedfrom a word processing program. Similarly, if one document is on paperand the other is an electronic text file, the paper document may be OCRscanned to provide a second electronic text file forcharacter-by-character comparison with the text file that was availableinitially. However, OCR scanning can produce artifacts and discrepancieseven where the two paper documents were identical (or where a paperdocument was printed from the text file to which it is to be compared),so that human review or “clean up” may be required. Also,character-by-character comparison may be impractical as to non-textportions of a document, such as graphs, charts and/or diagrams.

SUMMARY

According to an aspect of the invention, a method includes scanning apage of a paper document to generate a first digital page image. Thefirst digital page image is formed of first pixels. The method furtherincludes obtaining a second digital page image which corresponds to asecond page. The second digital page image is formed of second pixels.The method also includes comparing the first digital page imagepixel-by-pixel with the second digital page image to generate a scorethat indicates a degree to which the first digital page image differsfrom the second digital page image.

The obtaining of the second digital page image may include scanning apage of a paper document different from the paper document mentioned inthe previous paragraph, to generate the second digital page image.Alternatively, the second digital page image may be obtained by softwareconversion of an electronic text file such as a Microsoft Word documentinto a digital image file such as a “tiff” file or a “pdf” image file.As used herein and in the appended claims, an “electronic text file” isan electronic file that includes codes that represent text characters.Such a file may also incorporate non-text elements such as formatinstructions, images, tables, charts, graphs, etc.

Before the two digital page images are compared, either or both may besubjected to a deskewing algorithm. The offset and scale of one of thefiles may be adjusted to match the offset and scale of the other file.

Another process that may be performed prior to comparing the files is abrightness normalization. For example, the pixel values of the firstfile may be summed, the pixel values of the second file may be summed,and the resulting sums may be compared (e.g., divided), with theresulting quotient applied as a pixel value scaling factor to each pixelvalue in one of the files.

In another aspect of the invention, a method includes scanning all pagesof a multipage paper document to generate a first plurality of digitalpage images. Each of the digital page images is formed of pixels. Themethod further includes obtaining a second plurality of digital pageimages which corresponds to a multipage document to be compared with themultipage paper document. Each of the digital page images of the secondplurality is formed of pixels. In addition the method includes comparingeach page of the first plurality, pixel-by-pixel, with a respectivecorresponding page of the second plurality to generate for the page inquestion a respective score to indicate a degree to which the page inquestion differs from the respective corresponding page.

A page of one document “corresponds” to a page of another document ifboth pages occupy the same position in the respective documents. Forexample, the first page of one document corresponds to the first page ofthe other document, the second page of the first document mentionedcorresponds to the second page of the other document, and so forth.

The second plurality of digital page images may be obtained by scanninga multipage paper document or by converting an electronic text file todigital page images. Deskewing, scaling and offsetting (as well asbrightness normalization) may be performed with respect to one or bothof the pluralities of digital page images before the page-by-page,pixel-by-pixel comparisons are made.

The difference (or “sameness”) score for one page may be compared withthe score or scores for another page or pages. For example, such acomparison of scores may highlight a page which has different text fromits corresponding page in another document.

Respective electronic text files for the two documents may also becompared, character-by-character, for example, when the score or scoresfor the individual pages suggest that the two documents may not beidentical. Alternatively, text file comparison may come first, to befollowed by pixel-by-pixel comparison of the digital page images.

Individual lines of text in one document may be compared pixel-by-pixelwith corresponding lines in the other document to obtain per linesameness/difference scores. That is, in another aspect of the invention,a method includes scanning a page of a paper document to generate afirst digital page image. The first digital page image is formed offirst pixels which represent lines of text and a background. The methodfurther includes obtaining a second digital page image which correspondsto a second page. The second digital page image is formed of secondpixels which represent lines of text and a background. In addition, themethod includes comparing a line of text from the first digital pageimage with a corresponding line of text from the second digital pageimage to generate a score that indicates a degree to which the line oftext from the first digital page image differs from the line of textfrom the second digital page image.

Again, a line of text in one page “corresponds” to a line of text ofanother page if both lines occupy the same position in the respectivepages. For example, the first line of text of one page corresponds tothe first line of text of the other page, the second line of text of thefirst page mentioned corresponds to the second line of text of the otherpage, and so forth.

As before, the second digital page image may be obtained by scanning apaper document or by converting an electronic text file to a digitalpage image.

Therefore, it should now be apparent that the invention substantiallyachieves all the above aspects and advantages. Additional aspects andadvantages of the invention will be set forth in the description thatfollows, and in part will be obvious from the description, or may belearned by practice of the invention. Various features and embodimentsare further described in the following figures, description and claims.

DESCRIPTION OF THE DRAWINGS

The accompanying drawings illustrate presently preferred embodiments ofthe invention, and together with the general description given above andthe detailed description given below, serve to explain the principles ofthe invention. As shown throughout the drawings, like reference numeralsdesignate like or corresponding parts.

FIG. 1 is a simplified block diagram of a computer system which isprovided according to aspects of the present invention.

FIG. 2 is a flow chart that illustrates a process performed by thecomputer system of FIG. 1 according to aspects of the present invention.

FIG. 3 is a flow chart that illustrates some details of the process ofFIG. 2.

DETAILED DESCRIPTION

The present invention, in certain of its aspects, may provide animproved technique for comparing lengthy paper documents such ascontracts. Digital images are obtained by scanning the two documents,and a pixel-by-pixel comparison is performed of the resulting digitalimage to provide per page “sameness” scores. The comparison may followpre-processing of one or both images to improve the accuracy of thecomparison. The technique may also be adapted to compare a paperdocument with an electronic text file by scanning the paper document,converting the text file to a digital image file, and comparing the twodigital image files.

FIG. 1 is a simplified block diagram of a computer system 100 providedin accordance with aspects of the invention. The computer system 100 maybe entirely conventional in its hardware aspects, but may include and becontrolled by software to provide functionality as described below toimplement teachings hereof. In particular the hardware of the computersystem 100, and a portion of the software, may be such as is providedfor a conventional personal computer that includes a document scanner.

The computer system 100 includes a processor 102, which in practice maybe constituted by one or more conventional microprocessors. The computersystem 100 also includes one or more memory/storage devices (representedby block 104) which are in communication with the processor 102. Forexample, the memory/storage device(s) 104 may include read only memory(ROM), random access memory (RAM), flash memory, one or more hard diskdrives, drives for one or more removable disk-shaped storage media,etc., none of which is shown separately from block 104. Thememory/storage device(s) may function as both program and working memoryand may store various software programs, including for example anoperating system, a driver for a scanner (to be discussed below), a wordprocessing application such as Microsoft Word, an application forconverting word processing text files into digital images, and anapplication to provide the functionality described in connection withthe flow charts included herein.

Further, the computer system 100 includes a scanner 106 which is incommunication with the processor 102. As will be seen, the scanner 106may operate to capture images of documents to be compared to otherdocuments by the computer system 100 in accordance with aspects of theinvention. The scanner 106 itself may be entirely conventional, and mayfor example have a resolution of 600 dpi (dots per inch) or 1200 dpi. Insome embodiments, a scanner having higher resolution may be used. Insome embodiments, the scanner 106 may not be a direct peripheral devicein the computer system 100, but rather may be connected to the computersystem by a data network (not shown). In some embodiments, the scanner106 may be part of a larger device, such as a copier/printer.

In addition, the computer system may include other customaryinput/output devices, which may be in communication with the processor102 and which are represented by block 108 in the drawing. For example,the other input/output devices may include a keyboard, a mouse, adisplay device, and a printer, none of which are shown in the drawing.

FIG. 2 is a flow chart that illustrates a process performed by, or atleast partially with, the computer system 100 according to aspects ofthe present invention.

At 202 in FIG. 2, a paper document to be compared to another document isscanned, using the scanner 106, and the resulting digital page imagesare stored in the memory/storage device(s) 104. If the document that wasscanned is to be compared with another paper document, then the secondpaper document is also scanned at 202, and again the resulting digitalpage images are stored as a digital image file in the memory/storagedevice(s) 104. If the document that was scanned is to be comparedagainst a document that is stored in the form of an electronic text file(e.g., a Microsoft Word file), then a step 204 (indicated in phantom inFIG. 2) may also be performed. At step 204 the electronic text file isconverted to a digital image file. This may be done using conventionalsoftware stored in the computer system 100.

At 206, a deskew algorithm is applied by the computer system 100 to oneor both of the digital image files. In the deskew algorithm, which maybe performed in accordance with conventional principles, each digitalpage image of the digital image file is modified as required so that thelines of text in the digital page image are made parallel to the top andbottom edges of the digital page image. For example, the deskewalgorithm may seek a cluster of text or graphics in the digital pageimage, and then may compute the angle of white space between subsequentlines or features. Then the deskew algorithm reorients the content ofthe digital page image so that the white space angle remaps to zerodegrees.

At 208, an offset and scale algorithm is applied to each digital pageimage of one digital image file, so that the digital page image inquestion matches the offset and scale of the corresponding digital pageimage in the other digital image file. The offset is the distancebetween the left edge of the digital page image and the left edge of thelines of text on the digital page image. Thus, in effect, the text andother contents of one digital page image are shifted so that theleft-hand margin of the digital page image matches the left-hand marginof the corresponding digital page image in the other digital image file.In addition, the size of the content of the digital page image isadjusted (scaled) so that the overall height (e.g., top of first line oftext to bottom of last line of text) of the contents of the firstdigital page image is caused to match the overall height of thecorresponding digital page image of the other digital image file.

The pixels which make up each digital page image of each digital imagefile may be binary (i.e., may have values of “0” and “1” only, with “0”signifying a white pixel and “1” signifying a black pixel, for example),or may alternatively represent gray scale values (e.g., an 8-bit integerwith “0” representing white and “255” representing black, with othervalues in between representing shades of gray). If the pixels representgray scale values, then a brightness normalization algorithm may beapplied to normalize the brightness level of one digital image file tothe brightness level of the other digital image file. This step isindicated in phantom at 210.

Details of an example brightness normalization algorithm are illustratedin FIG. 3. At 302 in FIG. 3, the values of all of the pixels of adigital page image in one digital image file are summed to produce afirst sum. At 304 in FIG. 3, the values of all of the pixels of thecorresponding digital page image in the other digital image file aresummed to produce a second sum. At 306 in FIG. 3, the ratio of thesecond sum to the first sum is calculated. This ratio may be used as apixel value scaling factor, and may be applied (e.g., by multiplication)to each pixel value of the first digital page image, as indicated at 308in FIG. 3.

Referring again to FIG. 2, once the deskew, offset and scale adjustmentand brightness normalization (if needed) operations are performed, theprocess of FIG. 2 may continue with a pixel-by-pixel comparison of adigital page image of one digital image file to the correspondingdigital page image of the other digital image file, as indicated at 212in FIG. 2. It will be understood that the comparison may be performed bythe computer system 100 and particularly by the processor 102 operatingin conjunction with other components of the computer system 100. Thepurpose of the comparison is to calculate a score to indicate the degreeof difference (also to be considered the degree of sameness) between thetwo digital page images. A number of different formulae may be used tocalculate the difference score. For example, the following formula maybe used:

$\begin{matrix}{{X = {1 - {\sum\limits_{0}^{m}\frac{({Diff})}{m\left( {2^{n} - 1} \right)}}}},} & \left( {{Equation}\mspace{20mu} 1} \right)\end{matrix}$

where:

-   -   X is the difference score;    -   (Diff) is the absolute difference between the value of the        current pixel and the value of the corresponding pixel in the        corresponding page of the other digital image file;    -   m is the total number of pixels in each of the digital page        images being compared; and    -   n is the number of bits of gray scale resolution.

Where the pixel values are binary, n=1. If the comparison results in ascore X=1, then perfect correlation between the two digital page imagesis indicated. If the comparison results in a score X=0, then perfectinverse correlation between the two digital page images is indicated.(It will be appreciated that, except for a blank page, a score of X=1 isunlikely. Similarly, a score of X=0 is also—even more—unlikely.)

In some embodiments, as discussed below, corresponding regions withinthe page images, such as each line of text, may be compared to generatea sameness score for each region. In some embodiments, ifregion-by-region comparison is made, the page in question may be giventhe lowest of all the respective sameness scores calculated for theregions.

At 214 it is determined whether the score X calculated for a particularpage is higher than a threshold. If so, then the process results in aconclusion that the corresponding pages of the two documents are a matchfor each other, as indicated at 216. It is then determined at 218whether more pages remain to be compared between the two documents. Ifso, the process loops back to 212 and the next page-to-page comparisonif made. If not, the process ends (220).

Considering again the determination made at 214, if it is determinedthat the score obtained by comparing the two pages at 212 does notexceed the threshold, then further investigation may take place asindicated at 222. For example, comparative proofreading by one or twoindividual human beings may be performed with respect to the two pages.In addition or alternatively, an OCR process may be applied to the twopages, to be followed by a character-by-character comparison of the tworesulting electronic text files. (Of course, if a text file was alreadyavailable for one of the documents, it would not be necessary to performOCR processing with respect to that document before making thecharacter-by-character comparison between the two pages.) In addition oralternatively an image of the differences may be displayed forexamination.

Following step 222, if performed, the process then advances to theabove-discussed decision block 218, etc.

In addition to comparing the two documents page-by-page (andpixel-by-pixel within the page) to generate a sameness score relative tothe two pages compared, or as an alternative, the two documents may becompared line-by-line, at least to some extent, to generate a samenessscore for the respective corresponding lines of text in the two digitalimage files. For example, a line of text in one of the pages may becompared pixel-by-pixel with the corresponding line of text in the otherpage. In some embodiments, a line-by-line comparison may be made as partof the “further investigation” step 222 where the sameness score for thetwo pages failed to exceed the threshold. Line-by-line sameness scoresmay be generated for example where page-by-page sameness scores callinto question the sameness of the two documents. Where relatively lowpage-by-page sameness scores are suspected to have been caused only bydifferences in pagination, lines may be compared to lines thatcorrespond in position within the document as a whole, rather than basedon corresponding position within corresponding pages.

In some embodiments, the computer system 100 may compare the varioussameness scores for the pages and/or lines within the document to flagany page or line score or scores that are significantly lower than theother page or line scores. This may aid in locating particular pagesand/or lines at which differences in text are present between the twodocuments.

The flow charts included herein and the accompanying description shouldnot be understood to imply a fixed order of performing the indicatedmethod steps. Rather, the method steps may be performed in any orderthat is practicable. For example, referring to FIG. 2, step 204, ifperformed, may be performed prior to step 202.

In some embodiments, a more complex formula than Equation 1 may beemployed to calculate the difference score. For example, such a formulamay compensate for nonlinearities in the printing and/or scanning of thetwo documents.

In some embodiments, two paper documents may first be OCR-scanned andcompared character-by-character, and thereafter, if desirable, the twodocuments may be compared pixel-by-pixel, as described above, to confirmor overrule a result of the character-by-character comparison.

A number of embodiments of the present invention have been described.Nevertheless, it will be understood that various modifications may bemade without departing from the spirit and scope of the invention. Othervariations relating to implementation of the functions described hereincan also be implemented. Accordingly, other embodiments are within thescope of the following claims.

1. A method comprising: scanning a page of a paper document to generatea first digital page image, the first digital page image formed of firstpixels; obtaining a second digital page image which corresponds to asecond page, the second digital page image formed of second pixels; andcomparing the first digital page image pixel-by-pixel with the seconddigital page image to generate a score that indicates a degree to whichthe first digital page image differs from the second digital page image.2. The method according to claim 1, wherein: the paper document is afirst paper document; and the obtaining step includes scanning a page ofa second paper document to generate the second digital page image. 3.The method according to claim 1, wherein the obtaining step includesconverting an electronic text file to a digital image file.
 4. Themethod according to claim 1, further comprising: applying a deskewalgorithm to at least one of said digital page images before saidcomparing step.
 5. The method according to claim 4, further comprising:applying a deskew algorithm to both of said digital page images beforesaid comparing step.
 6. The method according to claim 1, furthercomprising: applying a brightness normalization algorithm whichincludes: calculating a sum of values of the first pixels; calculating asum of values of the second pixels; comparing said sums to generate apixel value scaling factor; and applying the pixel value scaling factorto all of the first pixels or to all of the second pixels; saidbrightness normalization algorithm being applied before said comparingstep.
 7. The method according to claim 1, further comprising: applyingan offset and scale algorithm in which an offset and a scale of one ofthe digital page images are adjusted to match an offset and a scale ofthe other of the digital page images, said offset and scale algorithmapplied before said comparing step.
 8. A method comprising: scanning allpages of a multipage paper document to generate a first plurality ofdigital page images, each of said digital page images formed of pixels;obtaining a second plurality of digital page images which corresponds toa multipage document to be compared with said multipage paper document,each of said digital page images of said second plurality formed ofpixels; and comparing each page of said first plurality, pixel-by-pixel,with a respective corresponding page of said second plurality togenerate for said each page a respective score to indicate a degree towhich said each page differs from said respective corresponding page. 9.The method according to claim 8, wherein: the multipage paper documentis a first multipage paper document; and the obtaining step includesscanning a second multipage paper document to generate the secondplurality of digital page images.
 10. The method according to claim 8,wherein the obtaining step includes converting an electronic text fileto a digital image file.
 11. The method according to claim 8, furthercomprising: deskewing, scaling and offsetting at least one of saidpluralities of digital page images before said comparing step.
 12. Themethod according to claim 8, further comprising: comparing one of saidscores with at least one other of said scores.
 13. The method accordingto claim 8, further comprising: obtaining a first electronic text filewhich corresponds to said multipage paper document; obtaining a secondelectronic text file which corresponds to said multipage document to becompared with said multipage paper document; and comparing said firstelectronic text file character-by-character with said second electronictext file.
 14. A method comprising: scanning a page of a paper documentto generate a first digital page image, the first digital page imageformed of first pixels which represent lines of text and a background;obtaining a second digital page image which corresponds to a secondpage, the second digital page image formed of second pixels whichrepresent lines of text and a background; and comparing a line of textfrom the first digital page image with a corresponding line of text fromthe second digital page image to generate a score that indicates adegree to which the line of text from the first digital page imagediffers from the line of text from the second digital page image. 15.The method according to claim 14, wherein: the paper document is a firstpaper document; and the obtaining step includes scanning a page of asecond paper document to generate the second digital page image.
 16. Themethod according to claim 14, wherein the obtaining step includesconverting an electronic text file to a digital image file.